<template>
  <a-dropdown position="br" @select="handleSelect($event, rowData)">
    <a-button type="text"
      ><icon-more-vertical class="icon-more-vertical"
    /></a-button>
    <template #content>
      <a-doption v-if="rowData.parentId !== '0'" value="move">
        <template #icon>
          <icon-drag-dot-vertical />
        </template>
        <template #default>移动</template>
      </a-doption>
      <a-doption v-if="rowData.parentId !== '0'" value="rename">
        <template #icon>
          <icon-pen />
        </template>
        <template #default>重命名</template>
      </a-doption>
      <a-doption value="share">
        <template #icon>
          <icon-share-alt />
        </template>
        <template #default>分享</template>
      </a-doption>
      <a-doption value="download">
        <template #icon>
          <icon-download />
        </template>
        <template #default>下载源文件</template>
      </a-doption>
      <a-doption value="approve">
        <template #icon>
          <icon-stamp />
        </template>
        <template #default>提交以供审阅</template>
      </a-doption>
      <a-doption value="createBypass">
        <template #icon>
          <icon-email />
        </template>
        <template #default>创建附函</template>
      </a-doption>
    </template>
  </a-dropdown>
</template>

<script lang="ts" setup>
  import { PropType } from 'vue';
  import { FileMessage, FileAndFolderMessage } from '@/api/tree-folder';
  import useFileManageStore from '@/store/modules/file-manage/index';
  import {
    move,
    share,
    downloadSource,
    approve,
    createBypass,
    rename,
  } from '../hooks/dropdow-events';

  const store = useFileManageStore();

  const props = defineProps({
    rowData: {
      type: Object as PropType<FileAndFolderMessage>,
      required: true,
    },
    rowIndex: {
      type: Number,
      required: true,
    },
  });

  // dropdown事件委托
  const handleSelect = (event: any, row: FileAndFolderMessage) => {
    const currentFile: FileMessage = row;
    store.setCurrentFIle(row);
    switch (event) {
      case 'move':
        move();
        break;
      case 'rename':
        rename(props.rowIndex);
        break;
      case 'share':
        console.log(currentFile);
        share(currentFile.id);
        break;
      case 'download':
        downloadSource(currentFile);
        break;
      case 'approve':
        approve(currentFile);
        break;
      case 'createBypass':
        createBypass(currentFile);
        break;
      default:
    }
  };
</script>
